package com.shengsiyuan.nio;

import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;

/**
 * Created by deng_wb on 2019/8/25
 * 文件锁: 共享锁: 所有程序都可以读写 排他锁: 只能有一个程序写,其他程序只读
 */
public class NioTest10 {

    public static void main(String[] args) throws Exception {
        RandomAccessFile accessFile = new RandomAccessFile("NioTest10.txt","rw");
        FileChannel fileChannel = accessFile.getChannel();
        FileLock fileLock = fileChannel.lock(3,6,true);
        System.out.println("valid: "+fileLock.isValid());
        System.out.println("lock type: "+fileLock.isShared());
        fileLock.release();
        accessFile.close();
    }
}
